#!/usr/bin/env bash
# Copyright (c) 2020 The Toltec Contributors
# SPDX-License-Identifier: MIT

pkgnames=(reboot-guard)
pkgdesc="Block systemd-initiated poweroff/reboot/halt until configurable condition checks pass"
url=https://github.com/stephanritscher/reboot-guard
pkgver=1.0.1-8
timestamp=2020-05-04T06:16Z
section="devel"
maintainer="Eeems <eeems@eeems.email>"
license=GPL-3.0
installdepends=(xochitl python3)

source=(
    https://github.com/stephanritscher/reboot-guard/archive/34d5df49d9fb914ab74d9b85d726aaa503b972a9.zip
    rguard.service
    rguard.patch
)
sha256sums=(
    b0a0af690d26dee6f00d03a0ed7573097bc06b867de5f7eef2222e8e6b9d3584
    SKIP
    SKIP
)

package() {
    patch "$srcdir"/rguard < "$srcdir"/rguard.patch
    install -D -m 644 "$srcdir"/rguard.service "$pkgdir"/etc/systemd/system/rguard.service
    install -D -m 755 "$srcdir"/rguard "$pkgdir"/opt/bin/rguard
}

configure() {
    systemctl daemon-reload
}

preremove() {
    disable-unit rguard.service
}

postremove() {
    systemctl daemon-reload
}
